package com.leased.handler;

import com.leased.exception.DatabaseException;
import com.leased.exception.YCException;
import com.leased.pojo.UserVerify;
import com.leased.request.cuser.CUserListRequest;
import com.leased.response.UserVerifyResponse;
import com.leased.service.UserAuthenticationService;
import com.leased.utils.Page;
import com.leased.utils.Validator;
import com.leased.utils.YCSystemStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by shencx on 2017/8/3.
 */
@Service
public class UserVerifyHandler {

    Logger LOG = LoggerFactory.getLogger(UserVerifyHandler.class);

    @Resource
    private UserAuthenticationService userAuthenticationService;

    /**
     * 车主认证列表
     * @param cUserListRequest
     * @return
     * @throws YCException
     */
    public Page<UserVerifyResponse> getUserVerifyPage(CUserListRequest cUserListRequest) throws YCException {
        Page<UserVerifyResponse> page = null;
        try {
            page = userAuthenticationService.fetchUserVerifyList(cUserListRequest);
            return page;
        } catch (DatabaseException e) {
            LOG.error("getUserVerifyPage exception",cUserListRequest);
            throw new YCException(YCSystemStatusEnum.INVOKE_API_RETURN_EXCEPTION.getCode(), YCSystemStatusEnum.INVOKE_API_RETURN_EXCEPTION.getDesc());
        }
    }

    /**
     * 更新审核状态
     * @param userVerify
     * @throws YCException
     */
    public void updateAuditStatus(UserVerify userVerify) throws YCException {
        /** 参数校验 */
        Validator.isEmpty(userVerify,YCSystemStatusEnum.PARAM_EMPTY);
        Validator.isEmpty(userVerify.getCuserId(),"主键ID不能为空");
        try {
            userAuthenticationService.updateUserVerifyInfo(userVerify);
        } catch (DatabaseException e) {
            LOG.error("updateAuditStatus exception",userVerify);
            throw new YCException(YCSystemStatusEnum.INVOKE_API_RETURN_EXCEPTION.getCode(), YCSystemStatusEnum.INVOKE_API_RETURN_EXCEPTION.getDesc());
        }
    }
}
